package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.constant.PageResult;
import com.itheima.constant.QueryPageBean;
import com.itheima.dao.MenuDao;
import com.itheima.domain.CheckItem;
import com.itheima.domain.Menu;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/10/14 20:47
 */
@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;

    //分页查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        Page<Menu> menu = menuDao.selectByCondition(queryString);
        long total = menu.getTotal();
        List<Menu> rows = menu.getResult();
        return new PageResult(total, rows);
    }

    //查询全部;
    @Override
    public List<Menu> findAll() {
        return menuDao.findAll();
    }

    //添加;
    @Override
    public void add(Menu menu) {
        menuDao.add(menu);
    }

    //删除
    @Override
    public void deleteByid(Integer id) {
        menuDao.deleteByid(id);
    }

    @Override
    public Menu findByid(Integer id) {
        return menuDao.findByid(id);
    }

    @Override
    public void update(Menu menu) {
        menuDao.update(menu);
    }

    @Override
    public List<Menu> getMenu(String name) {
        return menuDao.getMenu(name);
    }
}
